package com.zr.action;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.User;
import com.zr.service.UserService;



public class SignOutAction extends ActionSupport implements SessionAware,ServletRequestAware,ServletResponseAware{

	private HttpServletRequest req;
	private HttpServletResponse resp;
	private Map<String, Object> session;
	
	
	
	//属性注入
		@Resource
		private  UserService   userService;
	public void signOut() throws IOException{
		
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");	
		
		User u=(User) session.get("user");	
		
		 userService.updatesignOutSystem(u.getUid());
		 
		 HttpSession session =req.getSession();
	    session.invalidate();		
		Enumeration em = req.getSession().getAttributeNames();
		  while(em.hasMoreElements()){
		   req.getSession().removeAttribute(em.nextElement().toString());
		  }
		  resp.sendRedirect("index.jsp");
	

}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return super.execute();
	}
		
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.resp=arg0;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.req=arg0;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session=arg0;
	}

}
